package com.magicborrow.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.magicborrow.R;
import com.magicborrow.utils.ViewPressedUtil;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by ghost on 16/5/10.
 */
public class InputPriceDialog extends Dialog implements View.OnClickListener {
    private List<String> priceMode;

    private PickerView pv2;

    private Integer currentNumber;
    private String currentPriceMode;

    private EditText etNumber;

    public InputPriceDialog(Context context, List<String> priceMode) {
        super(context, R.style.msgDialog);
        this.priceMode = priceMode;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.price_dialog);
        setCanceledOnTouchOutside(true);
        //   findViewById(R.id.v_top).setOnClickListener(this);
        etNumber = (EditText) findViewById(R.id.et_price);

        findViewById(R.id.btn_cancel).setOnClickListener(this);
        findViewById(R.id.btn_cancel).setOnTouchListener(ViewPressedUtil.TouchPress);
        findViewById(R.id.btn_ok).setOnTouchListener(ViewPressedUtil.TouchPress);
        pv2 = (PickerView) findViewById(R.id.pv_string);

      /*  List<String> data2 = new ArrayList<>();
        data2.add("时");
        data2.add("天");*/
        pv2.setData(priceMode);
        currentPriceMode = priceMode.get(priceMode.size() / 2);


        pv2.setOnSelectListener(new PickerView.onSelectListener() {
            @Override
            public void onSelect(String text) {
                currentPriceMode = text;
            }
        });


    }

    public void setOnOkClickListener(View.OnClickListener listener) {
        findViewById(R.id.btn_ok).setOnClickListener(listener);

    }

    public int getTimeNumber() {
        String t = etNumber.getText().toString();
        if (t.matches("[0-9]{1,}"))
            currentNumber = Integer.valueOf(t);
        else {
            currentNumber = 0;
        }
       // currentNumber =  Double.valueOf(t);



        return currentNumber;
    }

    public String getCurrentPriceMode() {
        if (currentPriceMode == null)
            return "";

        return currentPriceMode;
    }


    @Override
    public void onClick(View v) {
        dismiss();
    }
}
